package main

import "fmt"

// Worker1101 :
// 求数组所有元素之和
func Worker1101(a [10]int) int {
	sum := 0
	for _, v := range a {
		sum += v
	}
	return sum
}

// Worker1102 :
/*
	找出数组中和为给定值的两个元素的下标，
	例如数组[1,3,5,8,7]，
	找出两个元素之和等于8的下标分别是（0，4）和（1，2）
*/
func Worker1102(a [5]int, num int) [][2]int {
	s := make([][2]int, 0, 2)
	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			if a[i]+a[j] == num {
				// fmt.Printf("%T, %T\n", i, j)
				// fmt.Printf("%v, %v\n", i, j)
				s = append(s, [2]int{i, j})
			}
		}
	}
	return s
}

func main() {
	fmt.Println("============= Worker1101 ================")
	a1 := [10]int{3, 5, 23, 33, 10, 9, 11, 34, 56, 89}
	result := Worker1101(a1)
	fmt.Println(result)
	fmt.Println("============= End 1101 ================")
	fmt.Println("============= Worker1102 ================")
	num := 8
	a2 := [...]int{1, 3, 5, 8, 7}
	result02 := Worker1102(a2, num)
	for _, group := range result02 {
		fmt.Printf("下标为 %v 的值是 %v 和下标为 %v 的值是 %v 的和是 %v\n",
			group[0],
			a2[group[0]],
			group[1],
			a2[group[1]],
			num,
		)
	}

	fmt.Println("============= End 1102 ================")
}
